package com.wellview.template.view;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;

import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;
import com.wellview.template.BaseActivity;
import com.wellview.template.R;
import com.wellview.template.widget.DoubleBallProgress;
import com.wellview.template.widget.X5WebView;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/2/5.
 */

public class ActionHandleActivity extends BaseActivity {

    private String url = "";
    private String action = "";
    public static final String ACTION_LOAD_URL = "@load_url";
    public static final String ACTION_SEND_BROADCAST = "@send_broadcast";

    @BindView(R.id.web_content)
    X5WebView webContent;
    @BindView(R.id.db_process)
    DoubleBallProgress dbProgress;
    @BindView(R.id.ll_nocontent)
    LinearLayout llNoContent;
    private String data;

    @Override
    protected void beforeShow(Bundle savedInstanceState) {
        Intent intent = getIntent();
        if (intent != null) {
            url = intent.getStringExtra("url");
            action = intent.getStringExtra("action");
            data = intent.getStringExtra("data");
        }
    }

    @Override
    public void bindView() {
        setContentView(R.layout.activity_action_handle);
    }

    @Override
    public void findAllViews() {

    }

    @Override
    public void setAllListeners() {

    }

    @Override
    public void doProcess() {
        if (TextUtils.isEmpty(action)){
            showNothingDisplay();
        }else {
            switch (action) {
                case ACTION_LOAD_URL:
                    loadUrl();
                    break;
            }
        }
    }

    private void showNothingDisplay() {
        llNoContent.setVisibility(View.VISIBLE);
        webContent.setVisibility(View.GONE);
    }

    private void loadUrl() {
        if (dbProgress != null) {
            dbProgress.setVisibility(View.VISIBLE);
        }
        webContent.setVisibility(View.VISIBLE);
        webContent.loadUrl(url);
        webContent.setGenerateCallBack(new X5WebView.GenerateCallBack() {
            @Override
            public void callProcess(WebView webView, int progress) {
                if (progress == 0) {
                    dbProgress.setVisibility(View.VISIBLE);
                }
                if (progress == 100) {
                    dbProgress.setVisibility(View.GONE);
                }
            }

            @Override
            public void onReceivedError(WebView webView, int i, String s, String s1) {
                dbProgress.setVisibility(View.GONE);
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();

    }
}
